Tips, Tricks and Techniques for boosting Shiny Development Productivity and Efficiency
Wednesday, September 20, 2023
Hello There!
In this lightning talk, we will touch base on the following high level topics to boost your R development experience.
renv or packrat to manage package dependencies.RStudio projects make it straightforward to divide your work into multiple contexts, each with their own working directory, workspace, history, and source documents.
Isolates your development environment.
Relative path referencing for your project files.
Segregate development flow and context.
Use your RStudio IDE Toolbar:
File –> New Project –> (Choose) New Directory/Existing Directory/Version Controlprofvisbrowser(), debug(function_name), and debug points.profvis to identify performance bottlenecks and Optimize critical sections of your code for speed.rbenchmark::benchmark().RStudio provides dozens of useful shortcuts that you can access through the menu at the top:
Tools > Keyboard Shortcuts Help.
RStudio Shortcuts Cheat sheet:
RStudio IDE Toolbar: Help –> Keyboard Shortcuts Help
Mac: Option + Shift + K
Windows: Alt + Shift + K
Comprehensive documentation and self help guides for using RStudio IDE Link
Using RStudio Projects. Link
Posit Cheat Sheets Link
profvis for code profiling and time estimation
My favourite Keyboard Shortcuts for R Development Workflow
Knowing how to toggle between panes without touching your mouse to move your cursor will help save time and improve your workflow. Use the following shortcuts to switch between panes seamlessly (Mac/Windows):
Control/Ctrl + 1: Source editor (your script)Control/Ctrl + 2: ConsoleControl/Ctrl + 3: HelpControl/Ctrl + 4: HistoryControl/Ctrl + 5: FilesControl/Ctrl + 6: PlotsControl/Ctrl + 7: PackagesControl/Ctrl + 8: EnvironmentControl/Ctrl + 9: ViewerIf you prefer to only have one pane in view at a time, add Shift to any of the previous commands to maximize the pane. Use the following shortcuts to bring a panes into primary focus seamlessly.
Control/Ctrl + Shift + 1: Source editor (your script) pane onlyControl/Ctrl + Shift + 2: Console pane onlyControl/Ctrl + Shift + 3: Help pane onlyControl/Ctrl + Shift + 4: History pane onlyControl/Ctrl + Shift + 5: Files pane onlyControl/Ctrl + Shift + 6: Plots pane onlyControl/Ctrl + Shift + 7: Packages pane onlyControl/Ctrl + Shift + 8: Environment pane onlyControl/Ctrl + Shift + 9: Viewer pane onlyWait! How do I go back to the classic four-pane view?
Control/Ctrl + Shift + 0 (Mac/Windows): Four-pane RStudio IDE View
| Description | Windows & Linux | Mac |
|---|---|---|
| Shift focus of cursor to Console | Ctrl + 2 |
Control + 2 |
| Clear Console | Ctrl + L |
Control + L |
| Move Cursor to beginning of a line | Home |
Cmd + Left |
| Move Cursor to end of a line | End |
Cmd + Right |
| Move Cursor to start/end of a word | Alt + Left/Rigth |
Option + Left/Right |
| Navigate command history | Up/Down |
Up/Down |
| Pop-up Command history | Ctrl + Up |
Cmd + Up |
| Description | Windows & Linux | Mac |
|---|---|---|
| Toggle document outline | Ctrl + Shift + O |
Cmd + Shift + O |
| Clear Console | Ctrl + L |
Control + L |
| New R Script | Ctrl + Shift + N |
Cmd + Shift + N |
| Save active document | Ctrl + S |
Cmd + S |
| Close active document | Ctrl + W |
Cmd + W |
| Knit and Preview Document (knitr) | Ctrl + Shift + K |
Cmd + Shift + K |
| Insert Chunk (Rmd) | Ctrl + Alt + I |
Cmd + Option + I |
| Description | Windows & Linux | Mac |
|---|---|---|
| Find and Replace | Ctrl + F |
Cmd + F |
| Find in Files | Ctrl + Shift + F |
Cmd + Shift + F |
| Description | Windows & Linux | Mac |
|---|---|---|
Insert Assignment Operator (<-) |
Alt + - (hyphen/minus) |
Option + - (hyphen/minus) |
Insert Pipe Operator (%>%) |
Ctrl + Shift + M |
Cmd + Shift + M |
| Description | Windows & Linux | Mac |
|---|---|---|
| Re-indent lines | Ctrl + I |
Cmd + I |
| Comment/un-comment current line/selection | Ctrl + Shift + C |
Cmd + Shift + C |
| Reformat Selection | Ctrl + Shift + A |
Cmd + Shift + A |
| Move Lines Up/Down | Alt + Up/Down |
Option + Up/Down |
| Jump to Matching Brace/Parenthesis | Ctrl + P |
Control + P |
| Add Cursor via drag | Alt + drag mouse pointer |
Option + drag mouse pointer |
| Delete Current Line | Ctrl + D |
Cmd + D |
| Insert Roxygen Skeleton | Ctrl + Alt + Shift + R |
Cmd + Option + Shift + R |
| Description | Windows & Linux | Mac |
|---|---|---|
| Move Focus to Terminal | Alt + Shift + M |
Shift + Option + M |
| New Terminal | Alt + Shift + R |
Shift + Option + R |
| Description | Windows & Linux | Mac |
|---|---|---|
| Restart R session | Ctrl + Shift + 0 |
Cmd + Shift + 0 |
R Ladies NYC - 23 September 2023